#include<stdio.h>

#include<stdlib.h>
int majorityElement(int* nums, int numsSize)
{      
    int i, num;
    int count = 0;

    for(i=0; i<numsSize; i++)
    {      
        if(count == 0)
        {      
            num = nums[i];
            count++;
        }
        else
        {      
            if(num == nums[i])
                count++;
            else
                count--;
        }
 }

    return num;
}      
int main(int argc, char **argv)
{      
    int * array;
    int n,i;
    printf("Please input the array size\n");
    scanf("%d",&n);
    array = (int*)malloc(sizeof(int)*n);
    for(i=0; i < n; i++)
    {      
        printf("Please input the %d-th number\n",i);
        scanf("%d",&array[i]);
    }


    int result = majorityElement(array, n);
    printf("values are %d\n", result);


}